from hitlist.lib.base import *
from pylons.database import make_session
from datetime import *

class TodoController(BaseController):

    def __before__(self):
        model.ctx.current = make_session()
    
    def index(self):
        c.tasks = model.Todo.select(model.Todo.c.status == 0)
        return render_response('/todo.mako')

    def add(self):
        """Add a new task to the todo list"""
        todo = model.Todo()
        todo.task = request.params.get('newtask', '')
        todo.tags = request.params.get('newtags', '')
        todo.flush()
        h.redirect_to(action='index')
        
    def complete(self):
        """complete a task from the task list"""
        todo = model.Todo.get_by(id=request.params.get('task_id'))
        todo.status = 1
        todo.flush()
        h.redirect_to(action='index')
    
    def list(self):
        """List all of the current todo items"""
        c.tasks = model.Todo.select()
        return render_response('/todo.mako')

